home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / whoami.arc / WHOAMI.PAS < prev   
Pascal/Delphi Source File  |  1986-05-07  |  2KB  |  52 lines

  1. program who_am_i;
  2.  
  3. { ****************************************************************
  4.  
  5.     This program locates its load name.  Starting with PC-DOS 3.0,
  6.     DOS records the load name at the end of the environment space:
  7.  
  8.            <environment string><0>
  9.            <environment string><0>
  10.              ...
  11.            <environment string><0>
  12.            <0>
  13.            <1><0>
  14.            <load name><0>
  15.  
  16.     So, to locate the load name we search for the two succesive
  17.     zeroes which terminate the environment string(s), then skip
  18.     tho bytes (<1><0>), then retrieve the load name.
  19.  
  20.               DOS VERSIONS PRIOR TO PC-DOS 3.0
  21.                 DO NOT RECORD THE LOAD NAME!
  22.  
  23.   ****************************************************************
  24.  
  25.    May 5, 1986.                  Compuserve ID:  [74166,1524]
  26.    Gary Maltzen.                         TC/PC:  612-545-5014
  27.                                                         Terrapin Station:  612-623-0152
  28.  
  29.    *************************************************************** }
  30. {$C+}
  31. var
  32.   e : integer;   { environment segment }
  33.   i : integer;   { offset within segment }
  34.   n : integer;   { count successive zero bytes }
  35.  
  36. begin
  37. e := memw[cseg:$2C];               { get environment segment }
  38. i := 0;                            { start at the beginning  }
  39. n := 0;                            { no zero bytes seen yet  }
  40. repeat
  41.   while mem[e:i] <> 0 do           { search a zero byte }
  42.     i := i+1;
  43.   i := i+1;
  44. until mem[e:i] = 0;                { stop at second zero byte }
  45. i := i+3;                          { skip to loaded file name }
  46. while (mem[e:i] <> 0) do           { display the load descriptor }
  47.   begin
  48.   write(chr(mem[e:i]));
  49.   i := i+1;
  50.   end;
  51. writeln;
  52. end.